
<!doctype html>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><note-list-component> ⌲ Examples ⌲ Basic</title>
    <link rel="stylesheet" href="../docs.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
    <link href="../prism-okaidia.css" rel="stylesheet" />
    <!-- <script type="module" src="../note-list-item-component.bundled.js"></script> -->
  </head>
  <body>
    
<header>
  <h1>&lt;note-list-item-component></h1>
  <h2>A container for note-list-item-component.</h2>
</header>
    
<nav>
  <a href="../">Home</a>
  <a href="">Examples</a>
  <a href="../api/">API</a>
  <a href="../install/">Install</a>
</nav>
    <div id="main-wrapper">
      <main>
        
    <h1>Example: Basic</h1>
    <section class="examples">
      <nav class="collection">
        <ul>
          
                  <li class=selected>
                    <a href="">A basic example</a>
                  </li>
                
                  <li class=>
                    <a href="name-property/">Setting the name property</a>
                  </li>
                
        </ul>
      </nav>
      <div>
        <script async type="module" src="http://unpkg.com/apress-simple-form-modal-component/dist/index.js"></script>
<script async type="module" src="http://unpkg.com/apress-book-web-components-note-list/dist/index.js"></script>
<script async type="module" src="http://unpkg.com/apress-note-list-item-component/dist/index.js"></script>
<div>
  <button id="myBtn">Open Modal</button>
  <simple-form-modal-component></simple-form-modal-component>
  <note-list-component></note-list-component>
</div>
<script>
  const myBtn = document.getElementById('myBtn');
  const formModal = document.querySelector('simple-form-modal-component');
  const noteList = document.querySelector('note-list-component');
  myBtn.addEventListener('click', function() {
    formModal.open = !formModal.open;
  });
  formModal.addEventListener('add-event', function(e) {
    let notes = noteList.notes;
    notes.push({title: e.detail.title, description: e.detail.description});
    noteList.notes = notes;
  });
</script>
<h3>HTML</h3>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>note-list-item-component</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>note-list-item-component</span><span class="token punctuation">></span></span></code></pre>
<pre class="language-js"><code class="language-js">  <span class="token keyword">const</span> myBtn <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'myBtn'</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br>  <span class="token keyword">const</span> formModal <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'simple-form-modal-component'</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br>  <span class="token keyword">const</span> noteList <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'note-list-component'</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br>  <span class="token keyword">const</span> allNotes <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">"title"</span><span class="token operator">:</span> <span class="token string">"Note 1"</span><span class="token punctuation">,</span> <span class="token string">"description"</span><span class="token operator">:</span> <span class="token string">'Loren Ipsum'</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">;</span><br><br>  noteList<span class="token punctuation">.</span>notes <span class="token operator">=</span> allNotes<span class="token punctuation">;</span><br>  myBtn<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><br>    formModal<span class="token punctuation">.</span>open <span class="token operator">=</span> <span class="token operator">!</span>formModal<span class="token punctuation">.</span>open<span class="token punctuation">;</span><br>  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br>  formModal<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'add-event'</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><br>    <span class="token keyword">let</span> notes <span class="token operator">=</span> noteList<span class="token punctuation">.</span>notes<span class="token punctuation">;</span><br><br>    notes<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span>title<span class="token operator">:</span> e<span class="token punctuation">.</span>detail<span class="token punctuation">.</span>title<span class="token punctuation">,</span> description<span class="token operator">:</span> e<span class="token punctuation">.</span>detail<span class="token punctuation">.</span>description<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br>    noteList<span class="token punctuation">.</span><span class="token function">setAttribute</span><span class="token punctuation">(</span><span class="token string">'notes'</span><span class="token punctuation">,</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>notes<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br>  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>

      </div>
    </section>
  
      </main>
    </div>
    
<footer>
  <p>
    Made with Love.
  </p>
</footer>
  </body>
</html>